package com.yidu.DailyFinalTreatment.service.impl;

import com.yidu.BusinessParameters.entity.CashAccruedEntity;
import com.yidu.BusinessParameters.entity.SecurityAccruedEntity;
import com.yidu.DailyFinalTreatment.entity.BondInterestIncomeEntity;
import com.yidu.DailyFinalTreatment.entity.IncomePaymentEntity;
import com.yidu.DailyFinalTreatment.entity.PayTwoFeesEntity;
import com.yidu.DailyFinalTreatment.mapper.IncomePaymentMapper;
import com.yidu.DailyFinalTreatment.service.IncomePaymentService;
import com.yidu.StockControl.entity.CashInventory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@Transactional
public class IncomePaymentImpl implements IncomePaymentService {

    @Autowired
    IncomePaymentMapper mapper;

    @Override
    public List<IncomePaymentEntity> selectCashInterestIncome(int page, int limit,String date) {

        Map map = new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        if (date!=null && !date.equals("")) {
            map.put("date","cashInventoryTime= "+date(date));

        }else{
            map.put("date","1=1");
        }
        List<IncomePaymentEntity> incomePaymentList = mapper.selectCashInterestIncome(map);
        return incomePaymentList;
    }

    @Override
    public List<BondInterestIncomeEntity> selectBondInterestIncome(int page, int limit,String date) {
        Map map = new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        if (date!=null && !date.equals("")) {
            map.put("date","securityInventoryTime ="+date(date));
        }else{
            map.put("date","1=1");
        }

        List<BondInterestIncomeEntity> bondInterestIncomeEntities = mapper.selectBondInterestIncome(map);
        return bondInterestIncomeEntities;
    }

    @Override
    public List<PayTwoFeesEntity> selectPayTwoFees(int page, int limit,String date) {
        Map map = new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        if (date!=null && !date.equals("")) {
            map.put("date","cashInventoryTime ="+date(date));
            System.out.println("进入判断"+map.get("date"));

        }else{
            map.put("date","1=1");
        }

        List<PayTwoFeesEntity> payTwoFeesEntities = mapper.selectPayTwoFees(map);

        return payTwoFeesEntities;
    }

    @Override
    public List<String> selectBondInterestIncomeID(SecurityAccruedEntity bondInterestIncomeEntity) {
        List<String> s = mapper.selectBondInterestIncomeID(bondInterestIncomeEntity);
        return s;
    }

    @Override
    public int deleteBondInterestIncomeID(String securityInventoryId) {
        int i = mapper.deleteBondInterestIncomeID(securityInventoryId);
        return i;
    }

    @Override
    public List<CashAccruedEntity> cashAccruedID(CashAccruedEntity cashAccrued){
        return mapper.cashAccruedID(cashAccrued);
    }

    @Override
    public String date(String date)  {
        SimpleDateFormat sj = new SimpleDateFormat("yyyy-MM-dd");
        if (date!=null && !date.equals("")){
        Date d = null;
        try {
            d = sj.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);
        // calendar.add(Calendar.DATE, 1);
        //System.out.println("明天：" +      sj.format(calendar.getTime()));
        calendar.add(calendar.DATE, -1);
        System.out.println("昨天：" + sj.format(calendar.getTime()));
        return "'"+sj.format(calendar.getTime())+"'";
        }else {
            return "0000-00-00";
        }
    }



}
